<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let obj = {
            name: "张三",
            age: 20
        };
        obj[Symbol.iterator] = function (){
            // 定义数组索引
            let index = 0;
            // 定义返回的next方法
            return {
                next: function(){
                    // 获取对象的长度
                    // 将对象的值解析为数组
                    let objl = Object.values(obj);
                    // 判断什么时候循环结束
                    if(index < objl.length){
                        return {"value": objl[index++], "done": false};
                    } else {
                        return {"value": undefined, "done": true};
                    }
                }
            }
        }
        // 输出对象的值
        let iterobj = obj[Symbol.iterator]();
        console.log(iterobj.next());
        console.log(iterobj.next());
        console.log(iterobj.next());
        // 给对象添加for...of循环机制
        for (m of obj){
            console.log(m);
        }
    </script>
</body>
</html>